#ifndef HASHMAP_H_
#define HASHMAP_H_

#define HASHMAP_INIT_SIZE 1048576
#define HASHMAP_LOAD_MAX 5
#include<common.h>
#include<pthread.h>
/*
hashmap 支持动态哈希的哈希表
void hashmap_init();
int hashmap_del(char*,int);
int hashmap_set(char* ,int ,char*,int)
int hashmap_get(char*,int,char*)
暂时只实现这三个
*/

uint32_t hashfunc(char *key, int key_size);

struct hashnode{
    uint32_t hashcode;
    char *key;
    int keylen;
    char *val;
    int vallen;
    hashnode *nxt;
    hashnode(char*key,int keylen):hashcode(hashfunc(key,keylen)),key(key),keylen(keylen){}
    bool operator==(const hashnode &tmp)const{
        if(hashcode!=tmp.hashcode||keylen!=tmp.keylen)
            return false;
        for (int i = 0; i < keylen;i++) if(key[i]!=tmp.key[i])
                return false;
        return true;
    }
};


struct listhead{
    hashnode *nxt;
    int load;
    uint32_t localmask;
    pthread_rwlock_t rwl;
    bool expandflg;
    pthread_t expthread;
};
//bucket里面放的是链表头 listhead 链表头后面是hashnode组成的链表

#endif